package com.hust.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class MailUtil {

    @Autowired
    private  JavaMailSender javaMailSender;

    public  void sendDiscountMsg(String text,String theme,String sendTo){
        SimpleMailMessage discountMsg=new SimpleMailMessage();
        discountMsg.setFrom("1457757074@qq.com");
        discountMsg.setTo(sendTo);
        discountMsg.setSubject(theme);
        discountMsg.setText(text);
        try {
            javaMailSender.send(discountMsg);
            System.out.println("邮件发送成功");
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("邮件发送失败");
        }
    }
}
